import React from "react";
import { Link, Routes, Route, Outlet } from "react-router-dom";

const Home1 = () => {
  return <div>home1页面</div>;
};
const Home2 = () => {
  return <div>home2页面</div>;
};

const Home = () => {
  return (
    <>
      <div>这是首页</div>
      <ul>
        <li>
          <Link to="/home">首页1</Link>
        </li>
        <li>
          <Link to="/home/home2">首页2</Link>
        </li>
      </ul>

      <hr />

      {/* Outlet组件相当于路由内容的出口 */}
      <Outlet />
    </>
  );
};

const About = () => {
  return <div>这是关于页</div>;
};

const App = () => {
  return (
    <>
      <h2>react-router-v6-nest</h2>
      <ul>
        <li>
          <Link to="/home">首页</Link>
        </li>
        <li>
          <Link to="/about">关于页</Link>
        </li>
      </ul>

      <hr />

      <Routes>
        <Route path="/home" element={<Home />}>
          {/* Route可以直接嵌套，整个项目的所有路由都可以在一个文件进行管理了 */}
          {/* 嵌套的内容会在其子组件的Outlet组件处渲染 */}

          {/* index属性，表示子路由的路径和上一级路由的路径保持一致 */}
          <Route index element={<Home1 />}></Route>
          <Route path="home2" element={<Home2 />}></Route>
        </Route>
        <Route path="/about" element={<About />}></Route>
      </Routes>
    </>
  );
};

export default App;
